
// Copyright (C) 2009-2011 Luca Piccioni
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program.  If not, see <http://www.gnu.org/licenses/>.

using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Text;

#pragma warning disable 1572, 1573

namespace Derm.OpenGL {

	/// <summary>
	/// Implementation of the OpenGL specification 
	/// </summary>
	public unsafe partial class Glx : ProcLoader
	{

		/// <summary>
		/// Binding for glXCreateContextAttribsARB function.
		/// </summary>
		/// <param name="dpy">
		/// A <see cref="T:System.IntPtr"/>.
		/// </param>
		/// <param name="config">
		/// A <see cref="T:System.IntPtr"/>.
		/// </param>
		/// <param name="share_context">
		/// A <see cref="T:System.IntPtr"/>.
		/// </param>
		/// <param name="direct">
		/// A <see cref="T:System.Boolean"/>.
		/// </param>
		/// <param name="attrib_list">
		/// A <see cref="T:System.Int32*"/>.
		/// </param>
		public static IntPtr CreateContextAttribsARB(IntPtr dpy, IntPtr config, IntPtr share_context, bool direct, ref int[] attrib_list) {
			IntPtr retvalue;
			unsafe {
				fixed (int* fp_attrib_list = attrib_list)
				{
					if      (Delegates.pglXCreateContextAttribsARB != null)
						retvalue = (Delegates.pglXCreateContextAttribsARB(dpy, config, share_context, direct, fp_attrib_list));
					else
						throw new InvalidOperationException("binding point CreateContextAttribsARB cannot be found");
				}
			}
			LogProc("glXCreateContextAttribsARB({0}, {1}, {2}, {3}, {4}) = {5}", dpy, config, share_context, direct, attrib_list, retvalue);
			return (retvalue);
		}

		/// <summary>
		/// Binding for glXGetProcAddressARB function.
		/// </summary>
		/// <param name="procName">
		/// A <see cref="T:System.Byte*"/>.
		/// </param>
		public static IntPtr GetProcAddressARB(ref byte[] procName) {
			IntPtr retvalue;
			unsafe {
				fixed (byte* fp_procName = procName)
				{
					if      (Delegates.pglXGetProcAddressARB != null)
						retvalue = (Delegates.pglXGetProcAddressARB(fp_procName));
					else
						throw new InvalidOperationException("binding point GetProcAddressARB cannot be found");
				}
			}
			LogProc("glXGetProcAddressARB({0}) = {1}", procName, retvalue);
			return (retvalue);
		}

		internal static partial class Delegates
		{
			[System.Security.SuppressUnmanagedCodeSecurity()]
			internal unsafe delegate IntPtr glXCreateContextAttribsARB(IntPtr dpy, IntPtr config, IntPtr share_context, bool direct, int* attrib_list);
			internal static glXCreateContextAttribsARB pglXCreateContextAttribsARB = null;

			[System.Security.SuppressUnmanagedCodeSecurity()]
			internal unsafe delegate IntPtr glXGetProcAddressARB(byte* procName);
			internal static glXGetProcAddressARB pglXGetProcAddressARB = null;

		}

		internal static partial class Imports
		{
			[System.Security.SuppressUnmanagedCodeSecurity()]
			[System.Runtime.InteropServices.DllImport(Library, EntryPoint = "glXCreateContextAttribsARB", ExactSpelling = true)]
			internal extern static unsafe IntPtr glXCreateContextAttribsARB(IntPtr dpy, IntPtr config, IntPtr share_context, bool direct, int* attrib_list);

			[System.Security.SuppressUnmanagedCodeSecurity()]
			[System.Runtime.InteropServices.DllImport(Library, EntryPoint = "glXGetProcAddressARB", ExactSpelling = true)]
			internal extern static unsafe IntPtr glXGetProcAddressARB(byte* procName);

		}

	}
}
